package net.boar.os;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zgl
 * @Date: 2021/6/23 11:03
 * @Description:
 */
public class OperatingSystemDay01 {
    private List<Integer> list = new ArrayList<>();
    private void readKernelFromFile(String fineName){
        File file = new File(fineName);
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            int tempbytes;
            while ((tempbytes = in.read()) != -1){
                list.add(tempbytes);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        list.add(0x55);
        list.add(0xaa);
        list.add(0xf0);
        list.add(0xff);
        list.add(0xff);
    }
    public OperatingSystemDay01(String s){
        readKernelFromFile("D:\\project\\MgOS\\code01\\boot.bat");
        int len = 0x168000;
        int cursize = list.size();
        for (int i = 0; i < len - cursize; i++) {
            list.add(0);
        }
    }
    public void makeFloppy(){
        try {
            DataOutputStream out = new DataOutputStream(new FileOutputStream("D:\\project\\MgOS\\code01\\system.img"));
            for (int i = 0; i < list.size(); i++) {
                out.write(list.get(i).byteValue());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //nasm -o boot.bat boot.asm
        wrapper();
        OperatingSystemDay02 op = new OperatingSystemDay02(getPath() + "boot.bat");
        op.makeFloppy();
    }
    private static void wrapper(){
        WorkerEntity entity = new WorkerEntity();
        entity.setCmd("nasm -o boot.bat boot.asm");
        entity.setWorkerPath(getPath());
        entity.setCreateBarName("build.bat");
        entity.setEncoding("GBK");
        Build.builder(entity);
    }
    private static String getPath(){
        return "D:\\project\\MgOS\\code02\\";
    }
}
